﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Scheduling.Models.Interfaces;
using Scheduling.Models.Helpers;
using Scheduling.Models.Repos.Database.Objects;


namespace Scheduling.Models.Repos.Database
{
    public class DatabaseRoomPropertyLoader : IRoomPropertyLoader
    {
        public List<RoomProperty> GetAllRoomProperties()
        {
            var db = DBContext.Create();
            var q = from c in db.Properties
                    select new { c = c };
            return LinqHelper.GenericMap<RoomProperty>(q, "c");
        }
        public void InsertRoomProperty(string Property)
        {
            var db = DBContext.Create();
            string command = string.Format("INSERT INTO Properties(ID)");
            db.ExecuteCommand(command);
        }


        public bool RoomPropertyExists(string name)
        {
            var db = DBContext.Create();
            foreach (var rp in db.Properties)
            {
                if (rp.Name == name)
                    return true;
            }
            return false;
        }

        public int GetPropertyID(string name)
        {
            var db = DBContext.Create();
            var result = from p in db.Properties where name == p.Name select p;
            if (result.ToList().Count > 0)
                return result.First().ID;
            else
                return -1;
        }

        public int GetHighestID()
        {
            var db = DBContext.Create();
            var result = from p in db.Properties select p;
            return result.ToList().Last().ID;
        }
    }
}